/*
 * Author: Jeff Liu(jebberwocky@gmail.com)
 * Date: Sep 5, 2010 7:16:04 PM
 * 
 * License: MIT
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
 * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 
 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
package net.citiport.ggltranslate.ggl;

import net.citiport.ggltranslate.core.Const;
import net.citiport.ggltranslate.util.WebUtil;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

public class GoogleLangAPI extends WebUtil {
	public static String TranslateText(String text, String langPair) throws UnsupportedEncodingException{
		if(text ==null)
			return null;
		else{
			text = URLEncoder.encode(text,Const.CHARSET);
			String query = Const.GOOGLE_LANG_TRANSLATE_URL + "?v=1.0&q=" + text + "&langpair=" + langPair;
			String result = getRequest(query);
			return result;
		}
    }
	
	public static String DetectLang(String text) throws UnsupportedEncodingException{
		if(text==null)
			return null;
		else{
			text = URLEncoder.encode(text,Const.CHARSET);
			String query = Const.GOOGLE_LANG_DETECT_URL + "?v=1.0&q=" + text;
			String result = getRequest(query);
			return result;

		}
	}
}
